﻿using System;
using System.Collections.Generic;
using System.Text;

using Microsoft.Xna.Framework;

using XRpgLibrary.ScriptClasses;
using XRpgLibrary.CharacterClasses;
using XRpgLibrary.TileEngine;

namespace XRpgLibrary.Scripts.Movement
{
    public class Follow : GameScript
    {
        private float outerRadius;
        private float innerRadius;

        public Follow(float outerRadius = 320f, float innerRadius = 64f)
        {
            this.outerRadius = outerRadius;
            this.innerRadius = innerRadius;
        }

        public override void Execute(Character self, object trigger, ScriptContext context, GameTime gameTime)
        {
            Vector2 deltaVector = context.Player.Sprite.Position - self.Sprite.Position;
            if (deltaVector.Length() < outerRadius && deltaVector.Length() > innerRadius)
            {
                deltaVector.Normalize();
                self.Move(deltaVector, (float)gameTime.ElapsedGameTime.TotalSeconds);
            }
            else
                self.Move(Vector2.Zero);
        }
    }
}
